Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: read in dependency charts #80

Merged
merged 6 commits into from
Sep 5, 2024
Merged

Conversation

qvalentin
Copy link
Collaborator

@qvalentin qvalentin commented May 17, 2024

This allows using the following of the dependency charts:

template files

  • you can use hover/go-to-definition on includes of dependencies e.g. name: {{ include "common.names.name" . }}

values files

  • you can use hover/completion/go-to-definition with the values of the dependencies e,g, example: {{ .Values.common.exampleValue }}

Todos:

  • Add note in readme that you should run helm dependency build
  • Add dependency charts to the chartstore
  • make sure values files are synced to disk
  • tests

Feedback would be welcome.
So if you want to test, clone this branch and run go build.

@qvalentin qvalentin mentioned this pull request May 17, 2024
@qvalentin qvalentin force-pushed the feature/dependecy-charts branch from 641df24 to 42c5fca Compare May 18, 2024 18:00
@qvalentin qvalentin force-pushed the feature/dependecy-charts branch 2 times, most recently from aa01386 to 2707018 Compare May 24, 2024 18:04
@qvalentin qvalentin force-pushed the feature/dependecy-charts branch 4 times, most recently from 137314c to 64267bb Compare July 1, 2024 18:56
@qvalentin qvalentin force-pushed the feature/dependecy-charts branch from 8458d6f to efc8a68 Compare July 21, 2024 15:44
@qvalentin qvalentin force-pushed the feature/dependecy-charts branch from c81c210 to 4350412 Compare August 20, 2024 17:32
@qvalentin qvalentin marked this pull request as ready for review August 25, 2024 21:20
@qvalentin qvalentin force-pushed the feature/dependecy-charts branch 2 times, most recently from 8b01935 to 16f269e Compare September 5, 2024 15:02
tests and cleanup

feat(hover): remove newlines in hover

fix(windows): test with different linebreaks

fix: test should work on windows now

minor changes

fix: minor change

fix: minor fixes

minor fix
@qvalentin qvalentin force-pushed the feature/dependecy-charts branch from 16f269e to 9b3ba2e Compare September 5, 2024 15:03
@qvalentin qvalentin merged commit 5b1dcc4 into master Sep 5, 2024
4 checks passed
@qvalentin qvalentin deleted the feature/dependecy-charts branch September 5, 2024 15:10
@dapc11
Copy link

dapc11 commented Sep 6, 2024

Does this include support for hovering and goto definition of TPL functions? From what I have tested it is working with values and dependency charts, but unfortunately not TPL files.. Any ideas?

It seems to be working within a single TPL file, I.e. goto functions that are defined within the current TPL file.

See example below:

_helper.tpl

{{- define "foo.bar" -}}
"hello-world-label"
{{- end -}}
{{- define "baz" -}}
"baz-{{ include "foo.bar" . }}""
{{- end -}}

pod.yaml

apiVersion: v1
kind: Pod
metadata:
  name: myapp
  labels:
    name: "{{ include "foo.bar" . }}"
spec:
  containers:
  - name: myapp
    image: myImage
    resources:
      limits:
        memory: "128Mi"
        cpu: "500m"
    ports:
      - containerPort: 123

Thanks for your work!

@qvalentin
Copy link
Collaborator Author

qvalentin commented Sep 6, 2024

Hi @dapc11, this should work, but I only tested it with the bitnami-common chart as a dependency (https://github.com/mrjosh/helm-ls/tree/master/testdata/dependenciesExample).
Your example does not even use dependencies, is this not working for you? For me it is:

image

Are you sure, you got the latest version of helm-ls?

@dapc11
Copy link

dapc11 commented Sep 6, 2024

Thanks for quick reply, yes I'm using the latest binary. However, you're right about the lack of dependency usage. My assumption is that when the tpl is "chart-local", i.e. part of the same templates folder it would snap it up automatically. But if you got it working it might be on my end that something is wrong. Will spend some additional time and get back to you.

Cheers!

@qvalentin
Copy link
Collaborator Author

Do you have a normal helm chart project structure, or are you using something like helmfile? I just deleted the Chart.yaml file in my example and this causes the same issue as you have stated.

@dapc11
Copy link

dapc11 commented Sep 6, 2024

It is a complex setup for sure. Could not really disclose it, unfortunately. But, I was able to reproduce with https://github.com/helm/examples, when I first tried to goto definition in deployment.yaml:
name: {{ include "hello-world.fullname" . }}
it succeeded as expected. But the second time, now doing it from serviceaccount.yaml:
name: {{ include "hello-world.serviceAccountName" . }}, the lsp process died. Can it be related to the template being encapsulated within conditions that the LSP have a hard time dealing with?

Here're the logs from the above test session:

[START][2024-09-06 15:20:29] LSP logging initiated
[WARN][2024-09-06 15:20:29] ...lsp/handlers.lua:135	"The language server yamlls triggers a registerCapability handler for workspace/didChangeConfiguration despite dynamicRegistration set to false. Report upstream, this warning is harmless"
[ERROR][2024-09-06 15:20:37] .../vim/lsp/rpc.lua:770	"rpc"	"~/.local/share/nvim/mason/bin/helm_ls"	"stderr"	'{"level":"info","msg":"helm-lint-langserver: connections opened","time":"2024-09-06T15:20:37+02:00"}\n'
[ERROR][2024-09-06 15:20:37] .../vim/lsp/rpc.lua:770	"rpc"	"~/.local/share/nvim/mason/bin/helm_ls"	"stderr"	'{"level":"info","msg":"Workspace configuration: {{true *.{yaml,yml} \\u003cbtree:[\\u003csuper\\u003e\\u003c-\\u003ctext:`.`\\u003e-\\u003e\\u003cany_of:[\\u003ctext:`yaml`\\u003e,\\u003ctext:`yml`\\u003e]\\u003e]\\u003e yaml-language-server 50 false {map[kubernetes:templates/**] true true {true https://www.schemastore.org/api/json/catalog.json}}} {values.yaml values.lint.yaml values*.yaml} info}","time":"2024-09-06T15:20:37+02:00"}\n'
[ERROR][2024-09-06 15:20:37] .../vim/lsp/rpc.lua:770	"rpc"	"~/.local/share/nvim/mason/bin/helm_ls"	"stderr"	'{"level":"info","msg":"Changing workspace config is not implemented","time":"2024-09-06T15:20:37+02:00"}\n'
[ERROR][2024-09-06 15:20:37] .../vim/lsp/rpc.lua:770	"rpc"	"~/.local/share/nvim/mason/bin/helm_ls"	"stderr"	'{"level":"error","msg":"Error loading values file ~/repos_personal/examples/charts/hello-world/values.lint.yaml open ~/repos_personal/examples/charts/hello-world/values.lint.yaml: no such file or directory","time":"2024-09-06T15:20:37+02:00"}\n'
[ERROR][2024-09-06 15:20:37] .../vim/lsp/rpc.lua:770	"rpc"	"~/.local/share/nvim/mason/bin/helm_ls"	"stderr"	'{"level":"info","msg":"helm lint: result for chart ~/repos_personal/examples/charts/hello-world : map[~/repos_personal/examples/charts/hello-world/Chart.yaml:[{{{0 0} {0 0}} Information \\u003cnil\\u003e \\u003cnil\\u003e Helm lint icon is recommended [] [] \\u003cnil\\u003e}]]","time":"2024-09-06T15:20:37+02:00"}\n'
[ERROR][2024-09-06 15:20:40] .../vim/lsp/rpc.lua:770	"rpc"	"~/.local/share/nvim/mason/bin/helm_ls"	"stderr"	'{"level":"info","msg":"helm lint: result for chart ~/repos_personal/examples/charts/hello-world : map[~/repos_personal/examples/charts/hello-world/Chart.yaml:[{{{0 0} {0 0}} Information \\u003cnil\\u003e \\u003cnil\\u003e Helm lint icon is recommended [] [] \\u003cnil\\u003e}]]","time":"2024-09-06T15:20:40+02:00"}\n'
[ERROR][2024-09-06 15:21:06] .../vim/lsp/rpc.lua:770	"rpc"	"~/.local/share/nvim/mason/bin/helm_ls"	"stderr"	'{"level":"info","msg":"helm-lint-langserver: connections opened","time":"2024-09-06T15:21:06+02:00"}\n'
[ERROR][2024-09-06 15:21:06] .../vim/lsp/rpc.lua:770	"rpc"	"~/.local/share/nvim/mason/bin/helm_ls"	"stderr"	'{"level":"info","msg":"Workspace configuration: {{true *.{yaml,yml} \\u003cbtree:[\\u003csuper\\u003e\\u003c-\\u003ctext:`.`\\u003e-\\u003e\\u003cany_of:[\\u003ctext:`yaml`\\u003e,\\u003ctext:`yml`\\u003e]\\u003e]\\u003e yaml-language-server 50 false {map[kubernetes:templates/**] true true {true https://www.schemastore.org/api/json/catalog.json}}} {values.yaml values.lint.yaml values*.yaml} info}","time":"2024-09-06T15:21:06+02:00"}\n'
[ERROR][2024-09-06 15:21:07] .../vim/lsp/rpc.lua:770	"rpc"	"~/.local/share/nvim/mason/bin/helm_ls"	"stderr"	'{"level":"info","msg":"Changing workspace config is not implemented","time":"2024-09-06T15:21:07+02:00"}\n'
[ERROR][2024-09-06 15:21:07] .../vim/lsp/rpc.lua:770	"rpc"	"~/.local/share/nvim/mason/bin/helm_ls"	"stderr"	'{"level":"error","msg":"Error loading values file ~/repos_personal/examples/charts/hello-world/values.lint.yaml open ~/repos_personal/examples/charts/hello-world/values.lint.yaml: no such file or directory","time":"2024-09-06T15:21:07+02:00"}\n'
[ERROR][2024-09-06 15:21:07] .../vim/lsp/rpc.lua:770	"rpc"	"~/.local/share/nvim/mason/bin/helm_ls"	"stderr"	'{"level":"info","msg":"helm lint: result for chart ~/repos_personal/examples/charts/hello-world : map[~/repos_personal/examples/charts/hello-world/Chart.yaml:[{{{0 0} {0 0}} Information \\u003cnil\\u003e \\u003cnil\\u003e Helm lint icon is recommended [] [] \\u003cnil\\u003e}]]","time":"2024-09-06T15:21:07+02:00"}\n'
[ERROR][2024-09-06 15:21:07] .../vim/lsp/rpc.lua:770	"rpc"	"~/.local/share/nvim/mason/bin/helm_ls"	"stderr"	'{"level":"info","msg":"Error calling yamlls for diagnostics write to stream: write data to conn: write /dev/stdout: file already closed","time":"2024-09-06T15:21:07+02:00"}\n'
[ERROR][2024-09-06 15:21:10] .../vim/lsp/rpc.lua:770	"rpc"	"~/.local/share/nvim/mason/bin/helm_ls"	"stderr"	'{"level":"info","msg":"Error calling yamlls for diagnostics write to stream: write data to conn: write /dev/stdout: file already closed","time":"2024-09-06T15:21:10+02:00"}\n'

@qvalentin
Copy link
Collaborator Author

Really weird, for me it is working without problems with https://github.com/helm/examples. Your logs also don't indicate a crash of helm-ls (there should be a stack trace).

@dapc11
Copy link

dapc11 commented Sep 6, 2024

Hmm, something is fishy here. What editor are you using? Mind sharing your setup?
Cheers

@qvalentin
Copy link
Collaborator Author

I'm using neovim (v0.10.1), maybe you can test with the minimal config
(https://github.com/mrjosh/helm-ls/blob/master/examples/nvim/init.lua)

nvim --clean -u helm-ls/examples/nvim/init.lua

I'm also pretty sure that this should work on macOS and linux

@dapc11
Copy link

dapc11 commented Sep 6, 2024

Will try and get back. Thanks for pointers!

@dapc11
Copy link

dapc11 commented Sep 6, 2024

It is definitely something on my end, both helm example and the more complex project is working as a charm with the example config. Thanks for your help and great contribution @qvalentin!

@qvalentin
Copy link
Collaborator Author

Good to know, feel free to ask, if you have any questions about the neovim config.

@dapc11
Copy link

dapc11 commented Sep 6, 2024

Funny story actually, have a quite sophisticated neovim setup, but have been trying out emacs lately, so now I'm stuck somewhere in between. Could be a reason for the issues I've had. Anyway great to have verified that it is on my end. Again great work.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants